<html>
<head><meta charset="utf-8"><title>rustfmt comment alignment · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustfmt.20comment.20alignment.html">rustfmt comment alignment</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="238962806"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustfmt%20comment%20alignment/near/238962806" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustfmt.20comment.20alignment.html#238962806">(May 16 2021 at 09:17)</a>:</h4>
<p>rustfmt just produced this diff for me</p>
<div class="codehilite" data-code-language="Diff"><pre><span></span><code><span class="gu">@@ -292,7 +367,7 @@ trait EvalContextExtPrivate&lt;'mir, 'tcx: 'mir&gt;: crate::MiriEvalContextExt&lt;'mir, '</span>
             immty_from_uint_checked(modified_sec, time_t_layout)?, // st_mtime
             immty_from_uint_checked(modified_nsec, long_layout)?, // st_mtime_nsec
             immty_from_uint_checked(0u128, time_t_layout)?, // st_ctime
<span class="gd">-            immty_from_uint_checked(0u128, long_layout)?, // st_ctime_nsec</span>
<span class="gi">+            immty_from_uint_checked(0u128, long_layout)?,  // st_ctime_nsec</span>
             immty_from_uint_checked(created_sec, time_t_layout)?, // st_birthtime
             immty_from_uint_checked(created_nsec, long_layout)?, // st_birthtime_nsec
             immty_from_uint_checked(metadata.size, off_t_layout)?, // st_size
</code></pre></div>
<p>I am quite puzzled by how it decided to vertically align <em>those two specific</em> comments but left all the others unchanged. I was also not able to find options/docs on this. Does anyone know the heuristics/rules rustfmt is using here?</p>



<a name="238968428"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustfmt%20comment%20alignment/near/238968428" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustfmt.20comment.20alignment.html#238968428">(May 16 2021 at 10:57)</a>:</h4>
<p>It doesn't seem to be aligning with anything either... you would need another space to line up with the previous line</p>



<a name="238970169"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustfmt%20comment%20alignment/near/238970169" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustfmt.20comment.20alignment.html#238970169">(May 16 2021 at 11:27)</a>:</h4>
<p>Oh right... that's even weirder then^^</p>



<a name="238974291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustfmt%20comment%20alignment/near/238974291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustfmt.20comment.20alignment.html#238974291">(May 16 2021 at 12:38)</a>:</h4>
<p>I have seen it place 2 spaces in front of end-of-line comments like that before</p>



<a name="238974294"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustfmt%20comment%20alignment/near/238974294" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustfmt.20comment.20alignment.html#238974294">(May 16 2021 at 12:39)</a>:</h4>
<p>it's weird that it isn't adjusting the rest of them the same way</p>



<a name="238975365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustfmt%20comment%20alignment/near/238975365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustfmt.20comment.20alignment.html#238975365">(May 16 2021 at 12:57)</a>:</h4>
<p>Cc <span class="user-mention" data-user-id="320317">@Caleb Cartwright</span></p>



<a name="238999630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustfmt%20comment%20alignment/near/238999630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Cartwright <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustfmt.20comment.20alignment.html#238999630">(May 16 2021 at 19:10)</a>:</h4>
<p>it's a little tough to tell from the inline snippet but it looks like it may be another presentation of a bug where rustfmt incorrectly attempts to align post comments vertically/visually (<a href="https://github.com/rust-lang/rustfmt/issues/4108">https://github.com/rust-lang/rustfmt/issues/4108</a>). that report was obviously for call args, but have seen it in other places that run through the same code paths.</p>
<p>it's an outright bug as rustfmt isn't supposed to do any vertical alignment by default</p>



<a name="239030545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustfmt%20comment%20alignment/near/239030545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustfmt.20comment.20alignment.html#239030545">(May 17 2021 at 04:03)</a>:</h4>
<p>I've seen this kind of thing happen as well in large multi-line lists.</p>



<a name="239146617"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustfmt%20comment%20alignment/near/239146617" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustfmt.20comment.20alignment.html#239146617">(May 17 2021 at 19:31)</a>:</h4>
<p>I added this example to <a href="https://github.com/rust-lang/rustfmt/issues/4108">https://github.com/rust-lang/rustfmt/issues/4108</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>